const mongoose = require('mongoose');
const { testedModel } = require('./../models/testedModel');
require('./../models/studentModel');

module.exports.saveTest = async function(req,res) {
    const result = await mongoose.model(testedModel).create(req.body);
    if (result) {
        res.send({
            message: "添加成功",
            code: 1
        });
    } else {
        res.send({
            message: "添加失败",
            code: 0
        });
    }
}

module.exports.getTested = async function(req,res) {
    const result = await mongoose.model(testedModel).find().populate('studentId').populate('testId');
    if(result){
        res.send({
            code: 1,
            message: '试卷信息获取成功',
            result: result
        });
    }else{
        res.send({
            code: 0,
            message: '信息获取失败'
        })
    }
}

module.exports.getTestResults = async function(req,res) {
    const result = await mongoose.model(testedModel).find({testId: req.body.testId}).populate('studentId').populate('testId');
    if(result){
        res.send({
            code: 1,
            message: '试卷信息获取成功',
            result: result
        });
    }else{
        res.send({
            code: 0,
            message: '信息获取失败'
        })
    }
}